package org.theflex.ui.search{
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	import flash.events.Event;
	import flash.events.KeyboardEvent;
	import flash.events.MouseEvent;
	
	import mx.containers.HBox;
	import mx.controls.Button;
	import mx.controls.TextInput;
	import mx.core.Application;
	import mx.events.FlexEvent;

	[Style(name="nextBtnStyleName", type="String")]
	[Style(name="previousBtnStyleName", type="String")]
	[Style(name="closeBtnStyleName", type="String")]
	
	public class UISearchFx extends HBox{
		private var _text:TextInput;
		private var _btnNext:Button;
		private var _btnPrevious:Button;
		private var _btnClose:Button;
		
		public function UISearchFx(){
			super();
		}
		
		override public function styleChanged(styleProp:String):void{
			super.styleChanged(styleProp);
			
			if(styleProp == "btnNextStyleName"){
				_btnNext.styleName = styleDeclaration.getStyle(styleProp);
			}else if(styleProp == "btnPreviousStyleName"){
				_btnPrevious.styleName = styleDeclaration.getStyle(styleProp);
			}else if(styleProp == "btnCloseStyleName"){
				_btnClose.styleName = styleDeclaration.getStyle(styleProp);
			}
		}
		
		override protected function createChildren():void{
			super.createChildren();
			
			_text = new TextInput();
			_text.addEventListener(Event.CHANGE, function(event:Event):void{
				UISearchManager.getInstance().clearDetacheds();
				UISearchManager.getInstance().clearResult();
			});
			
			_text.addEventListener(FlexEvent.ENTER, function(event:Event):void{
				UISearchManager.getInstance().find(_text.text);
			});
			
			addChild(_text);
			
			_btnNext = new Button();
			_btnNext.buttonMode = true;
			_btnNext.toolTip = "Próximo";
			//_btnNext.styleName = styleDeclaration.getStyle("btnNextStyleName");
			_btnNext.addEventListener(MouseEvent.CLICK, function(e:Event):void{
				
			});
			
			addChild(_btnNext);
				
			_btnPrevious = new Button();
			_btnPrevious.buttonMode = true;
			_btnPrevious.toolTip = "Anterior";
			//_btnPrevious.styleName = styleDeclaration.getStyle("btnPreviousStyleName");
			_btnPrevious.addEventListener(MouseEvent.CLICK, function(e:Event):void{
				
			});
			
			addChild(_btnPrevious);
				
			_btnClose = new Button();
			_btnClose.buttonMode = true;
			_btnClose.toolTip = "Fechar";
			//_btnClose.styleName = styleDeclaration.getStyle("btnCloseStyleName");
			_btnClose.addEventListener(MouseEvent.CLICK, function(e:Event):void{

			});
			
			addChild(_btnClose);	
		}
		
		override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void{
			super.updateDisplayList(unscaledWidth, unscaledHeight);
			
			/*if(_showAbsolute){
				y = (parent as DisplayObject).y;
				x = (parent as DisplayObject).width - unscaledWidth;
			}*/
		}
	}
}